package com.dao.impl;

import com.bean.Admin;
import com.bean.Notice;
import com.dao.BaseDao;
import com.dao.NoticeDao;
import com.utils.SqlUtils;

import java.util.List;
import java.util.Map;

public class NoticeDaoImpl extends BaseDao implements NoticeDao {
    String[] strings = {"AdminName"};
    @Override
    public List<Notice> selectForPageItems(int begin, int pageSize, String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.pageSql(Notice.class, Admin.class, strings);
        return queryForList(Notice.class, sql, content, begin, pageSize);
    }

    @Override
    public Integer selectForPageTotalCount(String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.countSql(Notice.class, Admin.class, strings);
        Number count = (Number) queryForSingleValue(sql, content);
        return count.intValue();
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete from `notice` where `id` = ?";
        return update(sql, id);
    }

    @Override
    public int insert(Notice notice) {
        Map.Entry<String, Object[]> entry = SqlUtils.insertSql(notice, strings);
        return update(entry.getKey(), entry.getValue());
    }

    @Override
    public Notice selectBy(Notice notice) {
        Map.Entry<String, Object[]> entry = SqlUtils.selectBy(notice, Admin.class, strings);
        return queryForOne(Notice.class, entry.getKey(),entry.getValue());
    }

    @Override
    public int updateByPrimaryKey(Notice notice) {
        Map.Entry<String, Object[]> entry = SqlUtils.updateSql(notice, strings);
        return update(entry.getKey(),entry.getValue());
    }
}
